home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Hashtable;
- import java.util.StringTokenizer;
-
- public final class URL {
- private static final String protocolPathProp = "java.protocol.handler.pkgs";
- private String protocol;
- private String host;
- private int port;
- private String file;
- private String ref;
- URLStreamHandler handler;
- static URLStreamHandlerFactory factory;
- static Hashtable handlers = new Hashtable();
-
- public URL(String var1, String var2, int var3, String var4) throws MalformedURLException {
- this.port = -1;
- this.protocol = var1;
- this.host = var2;
- this.file = var4;
- this.port = var3;
- if ((this.handler = getURLStreamHandler(var1)) == null) {
- throw new MalformedURLException("unknown protocol: " + var1);
- }
- }
-
- public URL(String var1, String var2, String var3) throws MalformedURLException {
- this(var1, var2, -1, var3);
- }
-
- public URL(String var1) throws MalformedURLException {
- this((URL)null, var1);
- }
-
- public URL(URL var1, String var2) throws MalformedURLException {
- this.port = -1;
- String var3 = var2;
- int var7 = 0;
- String var8 = null;
-
- try {
- int var5;
- for(var5 = var2.count; var5 > 0 && var2.charAt(var5 - 1) <= ' '; --var5) {
- }
-
- while(var7 < var5 && var2.charAt(var7) <= ' ') {
- ++var7;
- }
-
- if (var2.regionMatches(true, var7, "url:", 0, 4)) {
- var7 += 4;
- }
-
- char var6;
- for(int var4 = var7; var4 < var5 && (var6 = var2.charAt(var4)) != '/'; ++var4) {
- if (var6 == ':') {
- var8 = var2.substring(var7, var4).toLowerCase();
- var7 = var4 + 1;
- break;
- }
- }
-
- if (var1 == null || var8 != null && !var8.equals(var1.protocol)) {
- this.protocol = var8;
- } else {
- this.protocol = var1.protocol;
- this.host = var1.host;
- this.port = var1.port;
- this.file = var1.file;
- }
-
- if (this.protocol == null) {
- throw new MalformedURLException("no protocol: " + var3);
- } else if ((this.handler = getURLStreamHandler(this.protocol)) == null) {
- throw new MalformedURLException("unknown protocol: " + this.protocol);
- } else {
- int var12 = var2.indexOf(35, var7);
- if (var12 >= 0) {
- this.ref = var2.substring(var12 + 1, var5);
- var5 = var12;
- }
-
- this.handler.parseURL(this, var2, var7, var5);
- }
- } catch (MalformedURLException var10) {
- throw var10;
- } catch (Exception var11) {
- throw new MalformedURLException(var2 + ": " + var11);
- }
- }
-
- protected void set(String var1, String var2, int var3, String var4, String var5) {
- this.protocol = var1;
- this.host = var2;
- this.port = var3;
- this.file = var4;
- this.ref = var5;
- }
-
- public int getPort() {
- return this.port;
- }
-
- public String getProtocol() {
- return this.protocol;
- }
-
- public String getHost() {
- return this.host;
- }
-
- public String getFile() {
- return this.file;
- }
-
- public String getRef() {
- return this.ref;
- }
-
- public boolean equals(Object var1) {
- return var1 instanceof URL && this.sameFile((URL)var1);
- }
-
- public int hashCode() {
- int var1 = 0;
- if (!this.host.equals("")) {
- try {
- InetAddress var2 = InetAddress.getByName(this.host);
- var1 = var2.address;
- } catch (UnknownHostException var3) {
- }
- }
-
- return this.protocol.hashCode() ^ var1 ^ this.file.hashCode();
- }
-
- boolean hostsEqual(String var1, String var2) {
- if (var1.equals(var2)) {
- return true;
- } else {
- try {
- InetAddress var3 = InetAddress.getByName(var1);
- InetAddress var4 = InetAddress.getByName(var2);
- if (var4 != null && var4 instanceof InetAddress && (var4).address == var3.address) {
- return true;
- }
-
- return false;
- } catch (UnknownHostException var6) {
- } catch (SecurityException var7) {
- }
-
- return false;
- }
- }
-
- public boolean sameFile(URL var1) {
- return this.protocol.equals(var1.protocol) && this.hostsEqual(this.host, var1.host) && this.port == var1.port && this.file.equals(var1.file);
- }
-
- public String toString() {
- return this.handler.toExternalForm(this);
- }
-
- public String toExternalForm() {
- return this.handler.toExternalForm(this);
- }
-
- public URLConnection openConnection() throws IOException {
- return this.handler.openConnection(this);
- }
-
- public final InputStream openStream() throws IOException {
- return this.handler.openConnection(this).getInputStream();
- }
-
- public final Object getContent() throws IOException {
- return this.handler.openConnection(this).getContent();
- }
-
- public static synchronized void setURLStreamHandlerFactory(URLStreamHandlerFactory var0) {
- if (factory != null) {
- throw new Error("factory already defined");
- } else {
- SecurityManager var1 = System.security;
- if (var1 != null) {
- var1.checkSetFactory();
- }
-
- factory = var0;
- }
- }
-
- static synchronized URLStreamHandler getURLStreamHandler(String var0) {
- String var1 = var0;
- if (var0.equals("https")) {
- var1 = new String("http");
- }
-
- URLStreamHandler var2 = (URLStreamHandler)handlers.get(var1);
- if (var2 == null) {
- if (factory != null) {
- var2 = factory.createURLStreamHandler(var1);
- }
-
- if (var2 == null) {
- String var3 = System.getProperty("java.protocol.handler.pkgs", "");
- if (var3 != "") {
- var3 = var3 + "|";
- }
-
- var3 = var3 + "sun.net.www.protocol";
- StringTokenizer var4 = new StringTokenizer(var3, "|");
-
- while(var2 == null && var4.hasMoreTokens()) {
- String var5 = var4.nextToken().trim();
-
- try {
- String var6 = var5 + "." + var1 + ".Handler";
- var2 = (URLStreamHandler)Class.forName(var6).newInstance();
- } catch (Exception var7) {
- }
- }
- }
-
- if (var2 != null) {
- handlers.put(var1, var2);
- }
- }
-
- return var2;
- }
- }
-